/*
 * @Author: 我想吃余 483766615@qq.com
 * @Date: 2025-10-21 09:24:26
 * @LastEditors: 我想吃余 483766615@qq.com
 * @LastEditTime: 2025-10-22 10:22:09
 * @FilePath: /oscode/sha_mem/proc_b.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "comm.hpp"
#include "log.hpp"

int main()
{
    //获取共享内存
    int shmid = GetShm();
    //挂接该进程
    char* shmaddr = (char*)shmat(shmid, nullptr, 0);
    int fd = open(FIFO_FILE, O_WRONLY);
    if (fd < 0)
    {
        log(Fatal, "error string: %s, error code: %d", strerror(errno), errno);
        exit(FIFO_OPEN_ERR);
    }
    //开始通信
    while(true)
    {
        //直接访问共享内存
        cout<<"Please Enter@";  
        fgets(shmaddr, 4096, stdin);
        
        write(fd, "c", 1);//提醒对方，该接收消息了
    }
    //去挂接
    shmdt(shmaddr);
    return 0;
}